<?PHP

class community extends content
{
	
	var $playlists;
	var $galleries;
	var $articles;
	var $children;
	var $items;
	var $ekek;
	var $latest_video;
	var $shows;

	function community()
	{
		
		mp('loading community');
	}
	
	
	function get_ekek()
	{
		mp('getting ekek');
		unset($this->where);
		$this->where['type']='post';
		$this->where['category']=26;
		$this->get_content();
		$this->ekek=$this->data;
		

	}
	
	
	function get_piece()
	{
		global $conf;
		$category=new content_category();
		$category->where['id']=$conf->qm[1];
		$category->get_category();
		mp('got category');
		

		if($category->piece['type']=='video' && $category->piece['status']=='enabled')
		{
			mp('enabled video');
			$serial=unserialize($category->piece['serial']);
			$conf->style['masthead']=$category->piece['name'];
			$conf->style['background'].='background-image:url('.ap($serial["serial_style_background_image"]).');';
			$conf->style['background'].='background-color:#'.$serial["serial_style_background_color"].';';
			$conf->style['custom-masthead']=='color:#'.$serial["serial_style_masthead_color"].';';
			mp(ap($category->piece['image']));
				if(!empty($category->piece['image']))
				{
					$conf->style['masthead']='<img src="'.ap($category->piece['image']).'"/>';
				}
			
			$this->display=TRUE;
			$conf->page_render='assets/pages/'.$category->piece['page'].'.php';
		}
	}
	
	
	function get_galleries()
	{
		global $conf;
		mp('grab Galleries');
		$this->where['category']=$conf->qm[1];
		$this->where['type']='gallery';
		$this->get_content();
		$this->galleries=$this->data;

	}
	
	function get_videos()
	{
		mp('grab items');
		global $conf;
		$this->where['category']=$conf->qm[1];
		$this->where['type']='video';
		$this->items=$this->get_category_items($conf->qm[1]);
	}
	
	
	function get_children()
	{
		
		global $conf;
		$category=new content_category();
		unset($category->where);
		$category->where['parent']=$conf->qm[1];
		$category->where['status']='disabled';
		$category->get_category();
		$this->children=$category->data;
	}
	function get_trivia()
	{
		$sql = "select a.content from content as a, content_post as b where a.id = b.id and b.post_type ='todayinrock' ORDER BY a.start DESC";
		$result = mysql_query($sql);
		$r = "";
		$row = mysql_fetch_array($result);
		do
		{
			$r[] = $row; 	
		}while($row = mysql_fetch_array($result));
		$array = $r;
		shuffle($array);
		return current($array);
			
	}
	
	function get_poll()
	{
		$today = date("Y-m-d");
		$diff = time() + (7 * 24 * 60 * 60);
		$next_week = date("Y-m-d",$diff);
		$sql = "select * from poll where start<'$next_week' and start>=$today";
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
		return $row;
		
	}
	function get_poll_answers($id)
	{
		$r = "";
		$sql = "select * from poll_answer where question_id =$id ";
		$result = mysql_query($sql);
		while($row = mysql_fetch_array($result))
		{
			$r[] = $row;
		}
		return $r;
	}
	function get_poll_results($id)
	{
		$r = "";
		$sql = "select answer_id,count(id) from poll_votes where question_id =$id group by answer_id";
		$result = mysql_query($sql);
		while($row = mysql_fetch_array($result))
		{
			$r[$row['answer_id']] = $row;
		}
		
		return $r;
	}
	function check_voted($uid,$poll_id)
	{
	$today = date("Y-m-d");
	
	//Check if user has already voted today
		$sql = "select id from poll_votes where date_voted='$today' and user_id=$uid and question_id=$poll_id";
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
		if(empty($row))
			return false;
		else
			return true;
	}
}
?>
